<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>用户管理<small></small></h5>
                </div>
                <div class="ibox-content">
                    <div class="">
                        <a href="/admin/user/create" class="btn btn-primary ">添加</a>
                    </div>

                    {{--搜索分页代码块--}}
                    <div class="row">
                        <label class="adha-pro-pagelable">每页显示</label>
                        <form action="" method="get">
                            <div class="col-sm-2 m-b-xs">
                                <select name="pageSize" class="input-sm form-control input-s-sm inline">
                                    <option @if($pageSize==20) selected @endif value="20">20</option>
                                    <option @if($pageSize==50) selected @endif value="50">50</option>
                                    <option @if($pageSize==100) selected @endif value="100">100</option>
                                </select>
                            </div>
                            <label class="adha-pro-pagelable">条</label>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <input name="searchVal" value="@if(!empty($searchVal)){{$searchVal}}@endif"
                                           type="text" placeholder="请输入关键词" class="input-sm form-control"> <span class="input-group-btn">
                                            <button type="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
                                </div>
                            </div>
                        </form>
                    </div>


                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>姓名</th>
                            <th>邮箱</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($users as $user)
                        <tr class="gradeA">
                            <td>{{ $user->id }}</td>
                            <td>{{ $user->name }}</td>
                            <td>{{ $user->email }}</td>
                            <td class="center">

                                @if($user->id !=1)
                                <a href="/admin/user/edit?uid={{$user->id}}">编辑</a>
                                <a href="javascript:void(0);" class="delete-product" data-value="{{ $user->id }}" data-title="{{ $user->name }}">删除</a>
                                <a href="javascript:void(0);" class="reset-passwd" data-value="{{ $user->id }}" data-title="{{ $user->name }}">重置密码</a>
                                @endif
                            </td>
                        </tr>
                        @endforeach

                        </tbody>
                        <tfoot>
                            <tr>
                                <th>ID</th>
                                <th>姓名</th>
                                <th>邮箱</th>
                                <th>操作</th>
                            </tr>
                        </tfoot>
                    </table>
                    {{--分页--}}
                    <div>
                        <div class="pull-right">
                            {{ $users->appends(['pageSize'=>$pageSize,'searchVal'=>$searchVal])->render()  }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>

<script src="/js/plugins/layer/layer.min.js"></script>


<!-- Page-Level Scripts -->
<script>
    $(document).ready(function () {

        $('.delete-product').click(function () {
            var docuElem=$(this);
            var uid=docuElem.data('value');
            var title=docuElem.data('title');
            if(window.confirm('你确定删除'+ title+'？')){
                //继续执行
                $.ajaxSetup({
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
                });
                $.ajax({
                    type:'post',
                    url:'/admin/user/delete',
                    dataType:'json',
                    data:{uid:uid},
                    success: function(data){
                        data= eval(data);
                        if(data.code==200){
                            layer.msg(data.message, {icon: 6});
                            docuElem.parents('.gradeA').remove();
                        }
                        else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });


            }
        });

        $('.reset-passwd').click(function () {
            var docuElem=$(this);
            var uid=docuElem.data('value');
            var title=docuElem.data('title');
            if(window.confirm('确定为'+ title+'重置密码123456？')){
                //继续执行
                $.ajaxSetup({
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
                });
                $.ajax({
                    type:'post',
                    url:'/admin/user/resetPasswd',
                    dataType:'json',
                    data:{uid:uid},
                    success: function(data){
                        if(data.code==200){
                            layer.msg(data.message, {icon: 6});
                        }
                        else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });


            }
        });
        //====
        $("select[name='pageSize']").change(function () {
            $('form').submit();
        });


    });

</script>

</body>

</html>
